package Gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import Logic.LoginInfo;
import client.LibaryMain;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentListener;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.ImageIcon;
import com.toedter.calendar.JCalendar;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import org.jfree.ui.RefineryUtilities;
import java.awt.SystemColor;
import javax.swing.UIManager;
import javax.swing.JComboBox;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/**
 * this class implements gui of return reports
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class ReturnsReport extends JPanel {

private String enddate,startdate;
public   JPanel writepanel;
public static  JTextField textField,textField_1,textField_2,textField_3;
public static JComboBox<Object> comboBox1;

	
/**
 * Constractor
 */
	public ReturnsReport() {
		
		initcomponents();
	
	}
/**
 * this function create instance of return reports gui 
 */
	public void initcomponents()
	{
		JPanel showd=new JPanel();
	setBackground(new Color(153, 204, 255));
	setSize(1000,710);
	setLayout(null);
	
	JButton btnBack = new JButton("Back");
	btnBack.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			MainScreen.cardLayot.show(MainScreen.card, "reportmenu");
		}
	});
	btnBack.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13));
	btnBack.setBounds(39, 630, 97, 25);
	add(btnBack);
	
	JButton btnLogout = new JButton("Logout");
	btnLogout.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13));
	btnLogout.setBounds(669, 630, 97, 25);
	add(btnLogout);
	final JCalendar c = new JCalendar();
	c.setLocation(71, 11);
	c.setSize(402, 227);
	add(c);
	final JCalendar c2 = new JCalendar();
	c2.setLocation(543, 11);
	c2.setSize(386, 227);
	add(c2);
	
	JLabel lblFrom = new JLabel("From:");
	lblFrom.setFont(new Font("Tahoma", Font.BOLD, 20));
	lblFrom.setBounds(10, 11, 97, 25);
	add(lblFrom);
	
	JLabel lblTo = new JLabel("To:");
	lblTo.setFont(new Font("Tahoma", Font.BOLD, 20));
	lblTo.setBounds(502, 11, 75, 37);
	add(lblTo);
	
	JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
	tabbedPane.setBackground((new Color(100, 200, 250)));
	tabbedPane.setFont(new Font("Tahoma", Font.BOLD, 25));
	tabbedPane.setBounds(39, 249, 877, 370);
	add(tabbedPane);
	
	JPanel panel = new JPanel();
	panel.setBackground(UIManager.getColor("InternalFrame.activeTitleGradient"));
	tabbedPane.addTab("Global Delays Report", null, panel, null);
	panel.setLayout(null);
	
	textField = new JTextField();
	textField.setBounds(292, 130, 155, 32);
	textField.setColumns(10);
	panel.add(textField);
	
		textField_1 = new JTextField();
		textField_1.setBounds(292, 173, 155, 32);
		panel.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblAverege = new JLabel("Averege is :");
		lblAverege.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblAverege.setBounds(168, 133, 100, 23);
		panel.add(lblAverege);
		
		JLabel lblMedianIs = new JLabel("Median is:");
		lblMedianIs.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblMedianIs.setBounds(182, 176, 100, 23);
		panel.add(lblMedianIs);
		
		JButton btnNewButton = new JButton("Generate Report");
		btnNewButton.setBounds(630, 105, 176, 120);
		panel.add(btnNewButton);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
				String formatted = format1.format(c.getDate());
				SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
				String formatted2 = format2.format(c2.getDate());
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.add("LatesReport");
				Arr.add(formatted);
				Arr.add(formatted2);
				LibaryMain.chat.handleMessageFromGui(Arr);
			}
		});
		btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 14));
	
	JPanel panel_1 = new JPanel();
	
	panel_1.setBackground(UIManager.getColor("InternalFrame.activeTitleGradient"));
	tabbedPane.addTab("By book Delays Report", null, panel_1, null);
	panel_1.setLayout(null);
	
	comboBox1 = new JComboBox<Object>();
	comboBox1.setBounds(339, 114, 187, 35);
	panel_1.add(comboBox1);
	
	

	
	
	JLabel lblBookForReport = new JLabel("Choose a Book for report :");
	lblBookForReport.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblBookForReport.setBounds(97, 117, 219, 25);
	panel_1.add(lblBookForReport);
	
	textField_2 = new JTextField();
	textField_2.setBounds(339, 177, 93, 35);
	panel_1.add(textField_2);
	textField_2.setColumns(10);
	
	textField_3 = new JTextField();
	textField_3.setBounds(339, 234, 93, 35);
	panel_1.add(textField_3);
	textField_3.setColumns(10);
	
	JLabel label = new JLabel("Averege is :");
	label.setFont(new Font("Tahoma", Font.BOLD, 16));
	label.setBounds(216, 181, 100, 23);
	panel_1.add(label);
	
	JLabel label_1 = new JLabel("Median is:");
	label_1.setFont(new Font("Tahoma", Font.BOLD, 16));
	label_1.setBounds(229, 238, 100, 23);
	panel_1.add(label_1);
	
	JButton button = new JButton("Generate report");
	button.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		//	if(comboBox1.isFocusOwner()){
			SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
			String formatted = format1.format(c.getDate());
			SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
			String formatted2 = format2.format(c2.getDate());
			ArrayList<String> Arrr=new ArrayList<String>();
			Arrr.add("LatesReportByBook");
			Arrr.add(formatted);
			Arrr.add(formatted2);
			Arrr.add((String) comboBox1.getSelectedItem());
			LibaryMain.chat.handleMessageFromGui(Arrr);
		//	}
		//	else JOptionPane.showMessageDialog(null, "Book Not Selected");
		}
	});
	button.setFont(new Font("Tahoma", Font.BOLD, 14));
	button.setBounds(625, 103, 176, 120);
	panel_1.add(button);
	
	JButton btnFillCombobox = new JButton("Fill Combobox");
	btnFillCombobox.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
			String formatted = format1.format(c.getDate());
			SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
			String formatted2 = format2.format(c2.getDate());
			ArrayList<String> Arr2=new ArrayList<String>();
		    Arr2.add("GetLatesBooks");
			Arr2.add(formatted);
			Arr2.add(formatted2);
	        LibaryMain.chat.handleMessageFromGui(Arr2);		
		}
	});
	btnFillCombobox.setFont(new Font("Tahoma", Font.BOLD, 13));
	btnFillCombobox.setBounds(339, 50, 138, 35);
	panel_1.add(btnFillCombobox);
	
	btnLogout.addActionListener(new java.awt.event.ActionListener() {      
        public void actionPerformed(java.awt.event.ActionEvent ev) {
        	btnLogOut(ev);				
		}
        
		private void btnLogOut(ActionEvent ev) {
			ArrayList<String> Arr3=new ArrayList<String>();
			Arr3.add("Logout");
			Arr3.add("Worker");
			Arr3.add(LoginInfo.UserName);
			LibaryMain.chat.handleMessageFromGui(Arr3);
			MainScreen.cardLayot.show(MainScreen.card, "Login");
			
		}
    });
	}
/**
 * this function inserts average and median to global report gui 
 * @param str
 */
	public static void showmed(String[] str) {
		textField.setText(str[1]);
		textField_1.setText(str[2]);
		System.out.println(str[1]);
		System.out.println(str[2]);
	}
/**
 * this function inserts average and median to by book report gui 
 * @param str
 */
	public static void showbybook(String[] str) {
		textField_2.setText(str[1]);
		textField_3.setText(str[2]);
	}
/**
 * this function inserts books with delays to combobox in gui 
 * @param str
 */
	public static void fillcombobox(String[] str) {
		comboBox1.removeAllItems();
		for ( int w = 1 ; w <= str.length-1; w=w+1)
			comboBox1.addItem(str[w]);
	}

		
}
